from fastapi import APIRouter, Depends
from typing import List
from app.models.item import Item, ItemCreate, ItemUpdate
from app.services.item_service import ItemService, get_item_service

router = APIRouter(
    prefix="/items",
    tags=["items"]
)

@router.get("/", response_model=List[Item])
async def get_items(item_service: ItemService = Depends(get_item_service)):
    return item_service.get_all_items()

@router.get("/{item_id}", response_model=Item)
async def get_item(item_id: int, item_service: ItemService = Depends(get_item_service)):
    return item_service.get_item(item_id)

@router.post("/", response_model=Item)
async def create_item(item: ItemCreate, item_service: ItemService = Depends(get_item_service)):
    return item_service.create_item(item)

@router.put("/{item_id}", response_model=Item)
async def update_item(item_id: int, item: ItemUpdate, item_service: ItemService = Depends(get_item_service)):
    return item_service.update_item(item_id, item)

@router.delete("/{item_id}")
async def delete_item(item_id: int, item_service: ItemService = Depends(get_item_service)):
    item_service.delete_item(item_id)
    return {"message": "Item deleted successfully"} 